package lesson01;

import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TcpClientDemo02 {
    public static void main(String[] args) throws Exception {
        //1.创建一个Socket连接
        Socket socket=new Socket(InetAddress.getByName("192.168.137.1"),999);
        //2.创建一个输出流
        OutputStream os=socket.getOutputStream();
        //3.读取文件new File("tx.jpg")
        FileInputStream fis=new FileInputStream(new File("tx.jpg"));
        //4.写出文件
        byte[] buffer=new byte[1024];
        int len=fis.read(buffer);
        while(len!=-1){
            os.write(buffer,0,len);
        }
        //5.关闭资源
        fis.close();
        os.close();;
        socket.close();
    }
}
